import requests
from concurrent.futures import ThreadPoolExecutor

# 配置参数
URL = "http://47.122.114.21:8080/"  # 修改为你的服务器地址
REQUESTS = 10                 # 总请求数
CONCURRENCY = 1               # 并发线程数

success_count = 0
failed_count = 0

def send_request(_):
    global success_count, failed_count
    try:
        response = requests.get(URL, timeout=5)
        if response.status_code == 200:
            success_count += 1
        else:
            failed_count += 1
    except Exception as e:
        failed_count += 1

if __name__ == "__main__":
    print(f"开始压力测试，目标 {REQUESTS} 次请求，并发数 {CONCURRENCY}")
    
    with ThreadPoolExecutor(max_workers=CONCURRENCY) as executor:
        executor.map(send_request, range(REQUESTS))

    print("\n测试完成")
    print(f"成功请求: {success_count}")
    print(f"失败请求: {failed_count}")
    print(f"成功率: {(success_count/REQUESTS)*100:.2f}%")
